// components/pager/pager.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pageChange: {
      type: Function,
      default: () => {}
    },
    current: {
      type: Number,
      default: 1
    },
    showTotal: {
      type: Boolean,
      default: true,
    },
    total: {
      type: Number,
      default: 0,
    },
    hasNext: {
      type: Boolean,
      default: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    change(e){
      console.log('e',e)
      let type = e.currentTarget.dataset.id
      let page = this.data.current
      let hasNext = this.data.hasNext
      if(type == 'start'){
        if(page ==1){return}
        page = 1
      }else if(type == 'last'){
        if(page ==1){return}
        page = page >=1 ? 1 : (page- 1)
      }else if(type == 'next'){
        page = hasNext? (page +1) : page
      }
      this.triggerEvent('pageChange', page)
    }
  }
})
